<?php
session_start();
/*update query downn*/

$user_id = $_SESSION['user_id'];
//echo $user_id;

mysql_connect("localhost","root","");
mysql_select_db("susudo");

$select_users_query="SELECT * FROM users WHERE id=$user_id";
$select_profile_info_query="SELECT * FROM users_profile WHERE user_id=$user_id";
$select_users=mysql_query($select_users_query);
$select_profile=mysql_query($select_profile_info_query);
if ($select_profile && $select_users_query) {
    $row1 = mysql_fetch_assoc($select_users);
    $row2 = mysql_fetch_assoc($select_profile);
  // echo "<pre>";
  // print_r($row1);
  // print_r($row2);
  // echo "</pre>";
$select_users_and_profle_query="SELECT * FROM users JOIN users_profile ON users.id = users_profile.user_id WHERE `users`.id = `users_profile`.user_id";
//$select_profile_info_query="SELECT * FROM users_profile WHERE user_id=$user_id";
//$select_users=mysql_query($select_users_query);
$select_profile=mysql_query($select_users_and_profle_query);
       $row2 = mysql_fetch_assoc($select_profile);
}
if (isset($_POST['username'])) {
    $username = $_POST['username'];
}
if (isset($_POST['password'])) {
    $password = $_POST['password'];
}
if (isset($_POST['con_password'])) {
    $con_password = $_POST['con_password'];
}
if (isset($_POST['first_name'])) {
    $first_name = $_POST['first_name'];
}

if (isset($_POST['mid_name'])) {
    $mid_name = $_POST['mid_name'];
}

if (isset($_POST['last_name'])) {
    $last_name = $_POST['last_name'];
}
if (isset($_POST['gender'])) {
    $gender = $_POST['gender'];
}
if (isset($_POST['country'])) {
    $country = $_POST['country'];
}
if (isset($_POST['college'])) {
    $college = $_POST['college'];
}
if (isset($_POST['about'])) {
    $about = $_POST['about'];
}
    if($password !=$con_password) {
        echo "Password didn't match! Please type the exact same passwords";
    };

if ( $username != "" && $password != "" && $first_name != "" && $last_name != "" && $gender != "" && $country != "" && $college != "" && $about != "" ) {

        $fullname="$first_name $mid_name $last_name";
        $now = time();

        mysql_connect("localhost","root","");
        mysql_select_db("susudo");
$users_update_query="UPDATE `susudo`.`users` SET `username` = '$username',
`password` = '$password' WHERE `users`.`id` =$user_id";
 $users_profile_update_query="UPDATE `susudo`.`users_profile` SET
`about` = '$about',
`first_name` = '$first_name',
`mid_name` = '$mid_name',
`last_name` = '$last_name',
`gender` = '$gender',
`country` = '$country',
`college` = '$college'
 WHERE `users_profile`.`id`=$user_id";
$users_info=mysql_query($users_update_query);
$users_profile=mysql_query($users_profile_update_query);
  
$users_update_query="UPDATE users SET
`id`=' $user_id',
`username` = '$username',
`password` = '$password',
`email` = '$email',
`updated_at`='$now',
WHERE id=$user_id";

if(mysql_query($users_update_query))header("location: ../frontend.php?page=profile");

//if users_profile) {
   //row = mysql_fetch_assoc($users_profile);
   //echo "<pre>";
   // print_r($users_profile);
  //cho "</pre>";
  //}
     /*   $profile_edit_query="UPDATE * FROM users JOIN users_profile ON users.id=users_profile.user_id  SET `first_name` = '$first_name',
`mid_name` = '$mid_name',
`last_name` = '$last_name',
`gender` = '$gender',
`country` = '$country',
`college` = '$colz_work',
`website` = '$website' WHERE user_id=$user_id";  */
  }
?>